package com.journaldev.spring.util;

import java.beans.PropertyEditorSupport;

import com.journaldev.spring.model.PersonalOffice;
import com.journaldev.spring.model.UserInfo;
import com.journaldev.spring.service.UserInfoService;

public class SimpleUserEditor extends PropertyEditorSupport {
	
	private UserInfoService userInfoService;
	
	public SimpleUserEditor(UserInfoService service) {
		this.userInfoService = service;
		
	}

	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		// TODO Auto-generated method stub
		
		UserInfo userInfo = null;
        try {
            Integer id = Integer.parseInt(text);
            userInfo = userInfoService.getUserInfoById(id);
            System.out.println("User info :" + userInfo.getUserName());
        } catch (NumberFormatException ex) {
            System.out.println("userInfo will be null");
        }
        setValue(userInfo);
	}
}
